package com.yimi.yinhepda.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yimi.yinhepda.R;
import com.yimi.yinhepda.entity.bean.DispatchEntity;
import com.yimi.yinhepda.entity.response.DispatchScanResponse;

import java.util.List;

/**
 * @author 000432
 * @date 2017/4/22 0022
 */

public class DispactchScanAdapter extends BaseAdapter {

    List<DispatchEntity> dataList;
    private Context context;

    public DispactchScanAdapter(Context context, List<DispatchEntity> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return null != dataList ? dataList.size() : 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        DispatchEntity item = dataList.get(position);
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.load_scan_item4, null);
            // 运单号
            holder.waybillnum = (TextView) convertView.findViewById(R.id.text1);
            //开单
            holder.quantity = (TextView) convertView.findViewById(R.id.text3);
            // 已扫
            holder.scaned = (TextView) convertView.findViewById(R.id.text4);
            // 库存
            holder.stock = (TextView) convertView.findViewById(R.id.text5);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        // 运单号
        holder.waybillnum.setText(item.getWaybillNo() + "");
        //开单数
        holder.quantity.setText(item.getQuantity() + "");
        // 已扫
        holder.scaned.setText(item.getScanCount() + "");
        // 库存
        holder.stock.setText(item.getStoreQuantity() + "");
        switch (item.getType()) {
            case 0:
                convertView.setBackgroundColor(context.getResources().getColor(R.color.red));
                break;
            case 1:
                convertView.setBackgroundColor(context.getResources().getColor(R.color.white));
                break;
            case 2:
                convertView.setBackgroundColor(context.getResources().getColor(R.color.yellow));
                break;
            case 3:
                convertView.setBackgroundColor(context.getResources().getColor(R.color.green));
                break;
            default:
                break;
        }

        return convertView;
    }

    static class ViewHolder {
        /**
         * 运单号
         */
        TextView waybillnum;
        /**
         * 开单
         */
        TextView quantity;
        /**
         * 扫描
         */
        TextView scaned;
        /**
         * 库存
         */
        TextView stock;
    }

    @Override
    public Object getItem(int position) {
        // TODO 自动生成的方法存根
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO 自动生成的方法存根
        return 0;
    }

    public List<DispatchEntity> getDataList() {
        return dataList;
    }

    public void setDataList(List<DispatchEntity> dataList) {
        this.dataList = dataList;
    }
}
